/* namedpipe1.c (读取端) */
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>

#define FIFO_NAME "/tmp/myfifo"
#define BUFFER_SIZE 20

int main() {
    int fd;
    char buf[BUFFER_SIZE];
    
    /* 创建命名管道 */
    mkfifo(FIFO_NAME, 0666);
    
    /* 阻塞打开管道读端 */
    fd = open(FIFO_NAME, O_RDONLY);
    printf("Waiting for data...\n");
    
    /* 读取数据 */
    read(fd, buf, BUFFER_SIZE);
    printf("Received: %s\n", buf);
    
    close(fd);
    unlink(FIFO_NAME);
    return 0;
}
